package com.kxmall.web.controller.rider;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.common.core.controller.BaseRiderController;
import com.kxmall.common.exception.ServiceException;
import com.kxmall.system.service.ISysConfigService;
import com.kxmall.wechat.WxMaConfiguration;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kaixin
 * @version 1.0
 * @date 2023/9/23
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rider/app")
public class RiderMsValidateController extends BaseRiderController {

    private final ISysConfigService sysConfigService;

    /**
     * 消息验证
     *
     * @return 结果
     */
    @SaIgnore
    @RequestMapping("/validate_msg")
    public String validateMiniAppMsg(String signature, String timestamp, String nonce, String echostr) {
        WxMaService riderWxMaService = WxMaConfiguration.getRiderWxMaService();
        boolean b = riderWxMaService.checkSignature(signature, timestamp, nonce);
        if (!b) {
            throw new ServiceException("参数校验失败");
        }
        return echostr;
    }


}
